


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Pinky</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.npc.ghost</a>
</div>

<h1>Coverage Summary for Class: Pinky (nl.tudelft.jpacman.npc.ghost)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Pinky</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (3/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    84.6%
  </span>
  <span class="absValue">
    (11/13)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.npc.ghost;
&nbsp;
&nbsp;import java.util.List;
&nbsp;import java.util.Map;
&nbsp;import java.util.Optional;
&nbsp;
&nbsp;import nl.tudelft.jpacman.board.Direction;
&nbsp;import nl.tudelft.jpacman.board.Square;
&nbsp;import nl.tudelft.jpacman.board.Unit;
&nbsp;import nl.tudelft.jpacman.level.Player;
&nbsp;import nl.tudelft.jpacman.npc.Ghost;
&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
&nbsp;
&nbsp;/**
&nbsp; * &lt;p&gt;
&nbsp; * An implementation of the classic Pac-Man ghost Speedy.
&nbsp; * &lt;/p&gt;
&nbsp; * &lt;p&gt;
&nbsp; * Nickname: Pinky. Speedy gets his name for an unusual reason. Speedy appears
&nbsp; * to try to outsmart Pac-Man and crash into Pac-Man from the opposite
&nbsp; * direction. The truth behind this is that when Speedy isn&#39;t patrolling the
&nbsp; * top-left corner of the maze, he tries to attack Pac-Man by moving to where he
&nbsp; * is going to be (that is, a few spaces ahead of Pac-Man&#39;s current direction)
&nbsp; * instead of right where he is, as Blinky does. It&#39;s difficult to use this to
&nbsp; * your advantage, but it&#39;s possible. If Pinky is coming at you and you face a
&nbsp; * different direction, even briefly, he may just turn away and attempt to cut
&nbsp; * you off in the new direction while you return to your original direction. In
&nbsp; * the original Japanese version, his name is Machibuse/Pinky.
&nbsp; * &lt;/p&gt;
&nbsp; * &lt;p&gt;
&nbsp; * &lt;b&gt;AI:&lt;/b&gt; When the ghosts are not patrolling their home corners, Pinky wants
&nbsp; * to go to the place that is four grid spaces ahead of Pac-Man in the direction
&nbsp; * that Pac-Man is facing. If Pac-Man is facing down, Pinky wants to go to the
&nbsp; * location exactly four spaces below Pac-Man. Moving towards this place uses
&nbsp; * the same logic that Blinky uses to find Pac-Man&#39;s exact location. Pinky is
&nbsp; * affected by a targeting bug if Pac-Man is facing up - when he moves or faces
&nbsp; * up, Pinky tries moving towards a point up, and left, four spaces.
&nbsp; * &lt;/p&gt;
&nbsp; * &lt;p&gt;
&nbsp; * &lt;i&gt;Note: In the original arcade series, the ghosts&#39; genders are unspecified
&nbsp; * and assumed to be male. In 1999, the USA division of Namco and Namco Hometech
&nbsp; * developed the Pac-Man World series and declared Pinky to be female.&lt;/i&gt;
&nbsp; * &lt;/p&gt;
&nbsp; * &lt;p&gt;
&nbsp; * Source: http://strategywiki.org/wiki/Pac-Man/Getting_Started
&nbsp; * &lt;/p&gt;
&nbsp; *
&nbsp; * @author Jeroen Roosen 
&nbsp; *
&nbsp; */
<b class="fc">&nbsp;public class Pinky extends Ghost {</b>
&nbsp;
&nbsp;    private static final int SQUARES_AHEAD = 4;
&nbsp;
&nbsp;    /**
&nbsp;     * The variation in intervals, this makes the ghosts look more dynamic and
&nbsp;     * less predictable.
&nbsp;     */
&nbsp;    private static final int INTERVAL_VARIATION = 50;
&nbsp;
&nbsp;    /**
&nbsp;     * The base movement interval.
&nbsp;     */
&nbsp;    private static final int MOVE_INTERVAL = 200;
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new &quot;Pinky&quot;, a.k.a. &quot;Speedy&quot;.
&nbsp;     *
&nbsp;     * @param spriteMap
&nbsp;     *            The sprites for this ghost.
&nbsp;     */
&nbsp;    public Pinky(Map&lt;Direction, Sprite&gt; spriteMap) {
<b class="fc">&nbsp;        super(spriteMap, MOVE_INTERVAL, INTERVAL_VARIATION);</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * {@inheritDoc}
&nbsp;     *
&nbsp;     * &lt;p&gt;
&nbsp;     * When the ghosts are not patrolling their home corners, Pinky wants to go
&nbsp;     * to the place that is four grid spaces ahead of Pac-Man in the direction
&nbsp;     * that Pac-Man is facing. If Pac-Man is facing down, Pinky wants to go to
&nbsp;     * the location exactly four spaces below Pac-Man. Moving towards this place
&nbsp;     * uses the same logic that Blinky uses to find Pac-Man&#39;s exact location.
&nbsp;     * Pinky is affected by a targeting bug if Pac-Man is facing up - when he
&nbsp;     * moves or faces up, Pinky tries moving towards a point up, and left, four
&nbsp;     * spaces.
&nbsp;     * &lt;/p&gt;
&nbsp;     */
&nbsp;    @Override
&nbsp;    public Optional&lt;Direction&gt; nextAiMove() {
<b class="fc">&nbsp;        assert hasSquare();</b>
&nbsp;
<b class="fc">&nbsp;        Unit player = Navigation.findNearest(Player.class, getSquare());</b>
<b class="fc">&nbsp;        if (player == null) {</b>
<b class="nc">&nbsp;            return Optional.empty();</b>
&nbsp;        }
<b class="fc">&nbsp;        assert player.hasSquare();</b>
<b class="fc">&nbsp;        Square destination = player.squaresAheadOf(SQUARES_AHEAD);</b>
&nbsp;
<b class="fc">&nbsp;        List&lt;Direction&gt; path = Navigation.shortestPath(getSquare(), destination, this);</b>
<b class="fc">&nbsp;        if (path != null &amp;&amp; !path.isEmpty()) {</b>
<b class="fc">&nbsp;            return Optional.ofNullable(path.get(0));</b>
&nbsp;        }
<b class="nc">&nbsp;        return Optional.empty();</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-11 19:46</div>
</div>
</body>
</html>
